// ### 作业：建一个用户表（有姓名,年龄,性别,创建时间,修改时间）,使用模块加mysql模块,实现对数据的增删改查

// ###       修改时记得，把修改时间改成修改时的时间，能实现分页（选做）
let sql = require('mysql');
let mysql= sql.createConnection({host:'127.0.0.1',user:'root',password:'root',port:'3306',database:'user'})
mysql.connect();

//增
var newdate=new Date().toLocaleString(); //现在的时间
let addsql="INSERT INTO user VALUES('小丽',25,'女',"+newdate+","+newdate+",5);"
mysql.query(addsql,(err,date)=>{
    if(date!=undefined){
        console.log("添加成功");
    }
})

//删
let delsql="DELETE FROM user where id =2;"; 
mysql.query(delsql,(err,date)=>{
    if(date.affectedRows!=0){
        console.log("删除成功");
    }
})


//改
var newdate=new Date().toLocaleString();
let updatesql="UPDATE `user` SET NAME='小心' WHERE id=1;"
mysql.query(updatesql,(err,date)=>{
    if(date.affectedRows!=0){
        console.log("修改成功");
    }
})


//查
selectsql="SELECT*FROM user ORDER BY id DESC;"
mysql.query(selectsql,(err,date)=>{
    console.log(date);
})

mysql.end();



